package com.sky.controller.user;


import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "C端订单管理")
@RequestMapping("/user/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    //用户下单
    @PostMapping("/submit")
    public Result submit(@RequestBody OrdersSubmitDTO ordersCancelDTO) {
        //接收请求参数
        log.info("用户下单:{}", ordersCancelDTO);
        //调用service层的方法
        OrderSubmitVO orderSubmitVO = orderService.submit(ordersCancelDTO);
        //封装处理结果
        return Result.success(orderSubmitVO);
    }

    //历史订单查询
    @GetMapping("/historyOrders")
    public Result historyOrders(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("历史订单查询:{}", ordersPageQueryDTO);
        PageResult page = orderService.historyOrders(ordersPageQueryDTO);
        return Result.success(page);
    }

    //查询订单详情
    @GetMapping("/orderDetail/{id}")
    public Result querById(@PathVariable Long id) {
        OrderVO order = orderService.querById(id);
        return Result.success(order);
    }
    //取消订单
    @PutMapping("/cancel/{id}")
    public Result  cancel(@PathVariable Long id){
        orderService.cancel(id);
        return Result.success("取消成功");

    }
    //再来一单
    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable Long id){
        orderService.repetition(id);
        return Result.success("再来一单成功");

    }
    //用户催单
    @GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable Long id){
        orderService.reminder(id);
        return Result.success("催单成功");
    }

}
